package smartKiwi;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.JOptionPane;

public class SmartKiwiSystemTray {

	// start of main method
	public static void main(String[] args) {
		final SmartKiwi sk = new SmartKiwi();
		sk.loadConfiguration();
		sk.initSocketServer();
		final SmartKiwiHMIBuilder hmi = new SmartKiwiHMIBuilder(sk,Locale.FRANCE);
		hmi.setVisible(false);
		// checking for support
		if (!SystemTray.isSupported()) {
			System.out.println("System tray is not supported !!! ");
			return;
		}
		// get the systemTray of the system
		SystemTray systemTray = SystemTray.getSystemTray();

		Image image = Toolkit.getDefaultToolkit().getImage(
				"./src/images/smartkiwiico.ico");

		// popupmenu
		PopupMenu trayPopupMenu = new PopupMenu();

		// 1t menuitem for popupmenu
		MenuItem action = new MenuItem("Configurer");
		action.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				hmi.setVisible(true);
			}
		});
		trayPopupMenu.add(action);

		// 2nd menuitem of popupmenu
		MenuItem close = new MenuItem("Fermer");
		close.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		trayPopupMenu.add(close);

		// setting tray icon
		TrayIcon trayIcon = new TrayIcon(image, "SmartKiwi", trayPopupMenu);
		// adjust to default size as per system recommendation
		trayIcon.setImageAutoSize(true);

		try {
			systemTray.add(trayIcon);
		} catch (AWTException awtException) {
			awtException.printStackTrace();
		}
		System.out.println("end of main");

	}// end of main

}// end of class